<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <title>
        用户组管理
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/css/main.css}" media="all">
</head>

<body>
<div class="x-body">
    <form action="" method="post" class="layui-form layui-form-pane" id="auth_groupadd">
        <input type="hidden" name="id" th:value="${u_role.id}"/>
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red">*</span>角色编码
            </label>
                <div class="layui-input-inline" id="selectRoleCode">
                    <select id="u_role_code" name="role_code" >
                        <option  th:selected="${u_role.role_code.equals('vil_role01')}">vil_role01</option>
                        <option  th:selected="${u_role.role_code.equals('vil_role02')}">vil_role02</option>
                        <option  th:selected="${u_role.role_code.equals('vil_role03')}">vil_role03</option>
                    </select>
                </div>
        </div>
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red">*</span>角色名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="u_role_name" name="role_name"
                       class="layui-input" th:value="${u_role.role_name}">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="u_createdBy" class="layui-form-label">
                <span class="x-red" >*</span>创建者
            </label>
            <div class="layui-input-inline">
                <input type="text" id="u_createdBy" name="title"
                       class="layui-input" th:value="${u_role.createdBy}" readonly="true">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="1" title="启用" th:checked="${u_role.status==1}">
                <div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon layui-anim-scaleSpring"></i>
                    <div>启用</div>
                </div>
                <input type="radio" name="status" value="0" title="禁用" th:checked="${u_role.status==0}">
                <div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i>
                    <div>禁用</div>
                </div>


            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                拥有权限
            </label>
            <div class="layui-input-inline">
                <input type="text" id="u_describes" name="describes"
                       class="layui-input" th:value="${u_role.describes}" readonly='true'>
            </div>
        </div>
        <div class="layui-form-item">
            <button class="layui-btn" lay-submit="" lay-filter="add">保存</button>
        </div>
    </form>
</div>
<script th:src="@{/lib/layui/layui.js}" charset="utf-8">
</script>
<script th:src="@{/js/x-layui.js}" charset="utf-8">
</script>
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form()
            ,layer = layui.layer;


        $('#selectRoleCode').click(function () {
            // alert("1");
            var role_code = $('#u_role_code').val();
            if (role_code=='vil_role01') {
                $('#u_describes').val("拥有所有权限");
            } else if (role_code =='vil_role02') {
                $('#u_describes').val('拥有基础权限');
            } else {
                $('#u_describes').val('操作个人信息');
            }
        });
        //监听提交
        form.on('submit(add)', function(data){
            alert("www");
            // var auth_groupadd=$("#auth_groupadd").serialize();
            var role_code=$("select[name='role_code']").val();
            var data = data.field;
            if(role_code == ""){
                layer.msg("用户组编号不能为空",{icon:5,time:2000});
                return false;
            }
            $.ajax({
                type:"post",
                url:"/administrator/editGroup",
                data:data,
                dataType:"json",
                success:function (data) {
                    if(data.status==1){
                        layer.msg(data.msg,{icon:1,time:1000});
                        setTimeout(function(){
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        },1000);
                        return false;
                    }else{
                        layer.msg(data.msg,{icon:5,time:2000});return false;
                    }
                }
            })
            return false;
        });


    });
</script>


</body>

</html>